import pandas as pd

from backEnd.database import DBOperation


def select(table_name, key_name=[], key=[]):
    db = DBOperation.db_Operation()
    if not key_name:
        work, result = db.selectAll(table_name)
    else:
        work, result = db.select(table_name, key_name, key)
    db.close()
    return work, result


def select_page(table_name, limitNum, offsetNum):
    db = DBOperation.db_Operation()
    work, result = db.selectAllPage(table_name, ['id'], limitNum, offsetNum)
    db.close()
    return work, result


def delete(table_name, id):
    db = DBOperation.db_Operation()
    work, result = db.delete(table_name, ['id'], [id])
    db.close()
    return work, result


def update(table_name, key, data):
    db = DBOperation.db_Operation()
    work, result = db.update(table_name, ['id'], [key], data)
    db.close()
    return work, result


def select2page(table_name, table_name_2, limitNum, offsetNum):
    db = DBOperation.db_Operation()
    work, result = db.select2Page(table_name, table_name_2, ['date'], limitNum, offsetNum)
    db.close()
    return work, result


def select2(table_name, table_name_2, key_name=[], key=[]):
    db = DBOperation.db_Operation()
    work, result = db.select2(table_name, table_name_2, key_name, key)
    db.close()
    return work, result


if __name__ == "__main__":
    # x, y = select2('account_history', 'admin_history', ['name_operator'], ['admin'])
    # print(y)
    pass
